'''
Created on Apr 3, 2012

@author: wilshusensk
'''

class WebDataFormat(object):
    def __init__(self):
        self.dictionary = {}
    
    def addEntry(self, term, termPath):
        self.dictionary[term] = termPath
    
    def getTerms(self):
        return self.dictionary.keys()

    def getTermpath(self, term):
        return self.dictionary[term]

class SyntaxBeforeAndAfter(object):
    def __init__(self, syntaxBefore, syntaxAfter):
        self.syntaxBefore = syntaxBefore
        self.syntaxAfter = syntaxAfter
    
    def getSyntaxBefore(self):
        return self.syntaxBefore
    
    def getSyntaxAfter(self):
        return self.syntaxAfter

class PathToTerm(object):
    def __init__(self, listSyntaxAroundTerm):
        self.path = listSyntaxAroundTerm
    
    def getPathAsList(self):
        return self.path


def setupWebFormatConstellationSite(): 
    websiteFormat = WebDataFormat()
    rightAscensionTermPath = PathToTerm([SyntaxBeforeAndAfter("<body>", "</body>"), SyntaxBeforeAndAfter("<h2>Position in the Sky</h2>", "</ul>"), SyntaxBeforeAndAfter("ight Ascension: ", "hour")])
    declinationTermPath = PathToTerm([SyntaxBeforeAndAfter("<body>", "</body>"), SyntaxBeforeAndAfter("<h2>Position in the Sky</h2>", "</ul>"), SyntaxBeforeAndAfter("Declination: ", "degree")])
    titleTermPath = PathToTerm([SyntaxBeforeAndAfter("<body>", "</body>"), SyntaxBeforeAndAfter("<h1>*\s", "\s+</h1>")])
    websiteFormat.addEntry("rightAscension", rightAscensionTermPath)
    websiteFormat.addEntry("declination", declinationTermPath)
    websiteFormat.addEntry("title", titleTermPath)
    return websiteFormat

def setupWebFormatExoplanetSite(): 
    websiteFormat = WebDataFormat()
    rightAscensionTermPath = PathToTerm([SyntaxBeforeAndAfter("<html>", "</html>"), SyntaxBeforeAndAfter('Right&nbsp;Asc.&nbsp;Coord.</b></td><td align="left" bgcolor="#E4E0DC" style="border-left:#000000 1px solid;border-bottom:#000000 1px solid;">', "\s\d+\s\d+&nbsp;</td><td bgcolor=")])
    declinationTermPath = PathToTerm([SyntaxBeforeAndAfter("<html>", "</html>"), SyntaxBeforeAndAfter('Decl.&nbsp;Coord.</b></td><td align="left" bgcolor="#E4E0DC" style="border-left:#000000 1px solid;border-bottom:#000000 1px solid;">[+-]', '\s\d+\s\d+&nbsp;</td><td bgcolor="#E4E0DC" style="border-right:#000000')])
    titleTermPath = PathToTerm([SyntaxBeforeAndAfter("<html>", "</html>"), SyntaxBeforeAndAfter('color="#000000" size="6"><b>Star : ', "</b></font></td>")])
    websiteFormat.addEntry("rightAscension", rightAscensionTermPath)
    websiteFormat.addEntry("declination", declinationTermPath)
    websiteFormat.addEntry("title", titleTermPath)
    return websiteFormat